import {   mysqlTable,
    int,
    text,
    timestamp,
} from "drizzle-orm/mysql-core";
import { sql } from 'drizzle-orm';

export const userTable = mysqlTable('sys_user', {
    user_id: int('user_id').primaryKey().autoincrement().notNull(),
    dept_id: int('dept_id'),
    user_name: text('user_name').notNull(),
    nick_name: text('nick_name').notNull(),
    create_time: timestamp('create_time')
        .default(sql`CURRENT_TIMESTAMP`) // 插入时默认当前时间
        .notNull(),
    update_time: timestamp('update_time')
        .default(sql`CONVERT_TZ(NOW(), '+00:00', '+08:00')`) // 插入时默认当前时间
        .onUpdateNow() // 关键：更新记录时自动刷新为当前时间
        .notNull(),
})
export type User = typeof userTable.$inferSelect;
